package com.programmingeyeclient.user.controller;


import com.programmingeyeclient.user.common.Result;
import com.programmingeyeclient.user.entity.EduStudent;
import com.programmingeyeclient.user.service.EduStudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 控制层
 */
@RestController
@CrossOrigin
public class EduStudentController  {

    @Resource
    private EduStudentService eduStudentService;

    private static Map<String, EduStudent> tokenMap = new HashMap<>();

    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    @ResponseBody
    public Result login(EduStudent eduStudent, HttpServletRequest request){
        Result result=eduStudentService.findByUserName(eduStudent);
        if (result.getCode()==1){
            HttpSession session=request.getSession();
            session.setAttribute("userName",eduStudent.getUserName());
            session.setAttribute("passWord",eduStudent.getPassword());
//            session.getAttribute("userName");
        }
        return result;
    }

    /**
     * 判断接口 是否登录
     */
//    public String loginon(HttpServletRequest request){
////        HttpSession session= request.getSession();
////        if (session.getAttribute("userName") == ""){
////            session.getAttribute("false");
////        }
//
//    }

    /**
     * 注册
     * @param eduStudent
     * @return
     */
    @RequestMapping("/enroll")
    public Result enroll(@RequestBody EduStudent eduStudent){
        return eduStudentService.enroll(eduStudent);
    }


    /**
     * 修改用户信息
     * @param eduStudent 用户
     * @return eduStudent
     */
    @PostMapping("/Update")
    public Boolean Update(@RequestBody EduStudent eduStudent) {
        System.out.println("用户信息============>>>"+eduStudentService.getUpdate(eduStudent));
        return eduStudentService.getUpdate(eduStudent);
    }

    /**
     * 根据id查询
     * @param id 用户id
     * @return EduStudent
     */
    @GetMapping("userList")
    public EduStudent getstudentid(Integer id){
        return eduStudentService.getStudentid(id);
    }
}
